from ElectronicAssetModel import ElectronicAssetModel
from UserModel import UserModel
from util import session
from sys import maxsize

class AssetManageDao():
    @staticmethod
    def filter_user_devices_page(args, pageIndex: int = 1, pageSize: int = maxsize):
        if pageSize == maxsize and pageIndex > 1:
            raise Exception("page参数异常")
        else:
            return session.query(ElectronicAssetModel,UserModel).filter_by(**args[0]).outerjoin(UserModel, ElectronicAssetModel.user_id == UserModel.uuid)\
                .filter_by(**args[1])\
                .limit(pageSize).offset((pageIndex - 1) * pageSize)

    @staticmethod
    def filter_user_devices(args):
        return session.query(ElectronicAssetModel,UserModel).filter_by(**args[0]).outerjoin(UserModel, ElectronicAssetModel.user_id == UserModel.uuid).filter_by(**args[1])
